using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
using System.Collections.Generic;

[CustomEditor(typeof(ObjetoInteragivel))]
public class ObjetoInteragivelEditor : Editor {

	// Use this for initialization
	void Start () {
	
	}
	
	public override void OnInspectorGUI()
   { 
		DrawDefaultInspector ();
	   
		if(GUILayout.Button("Gerar Arquivos"))
		{
            ObjetoCenStruct obj = new ObjetoCenStruct();
            obj.Nome = ((ObjetoInteragivel)target).name; 
            obj.QuantidadeNecessaria = ((ObjetoInteragivel)target).quantidadeNecessaria; 
            obj.AtributoNecessario = (int) ((ObjetoInteragivel)target).atributoNecessario;
            obj.Posicao = new Vector2(((ObjetoInteragivel)target).transform.localPosition.x * 1280, ((ObjetoInteragivel)target).transform.localPosition.x * 720);
            //tile.renderer.material.name.Equals("Assoalho (Instance)")
            obj.Textura = ((ObjetoInteragivel)target).transform.renderer.material.mainTexture.name;
            Debug.Log(((ObjetoInteragivel)target).transform.localPosition.x * 1280 + " " + (((ObjetoInteragivel)target).transform.localPosition.x * 100));
            List<ObjetoStruct> list = new List<ObjetoStruct>();

            Objeto[] obs = GameObject.FindObjectsOfType(typeof(Objeto)) as Objeto[];

            Transform ta = (target as ObjetoInteragivel).transform.parent;

            for (int i = 0; i < ta.transform.childCount; i++)
            {
                Transform t = ta.transform.GetChild(i);
                Debug.Log(t.name);
                if(t.name.Equals("Objetos"))
                {
                    foreach(Objeto o in obs)
                    {
                        ObjetoStruct obst = new ObjetoStruct();
                        Debug.Log((t.localPosition.x * 100) + " " + (t.localPosition.x * 100));
                        obst.Nome = o.name;
                        obst.AtributoNecessario = (int)o.atributoNecessario;
                        obst.QuantidadeNecessaria = o.quantidadeNecessaria;
                        obst.Posicao = new Vector2(o.transform.position.x * 100, o.transform.position.z * -100);
                        obst.Textura = o.transform.renderer.material.mainTexture.name;
                        list.Add(obst );
                    }
                    break;
                }
            }

            SaveGame.Save(obj, list);
		}
        
   }
	
	// Update is called once per frame
	void Update () {
	
	}
}
